/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bgate.core;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;

/**
 *
 * @author user
 */
public abstract class Screen extends Canvas {

    public final static int TYPE_SCREEN240x320 = 0;
    public final static int TYPE_SCREEN320x240 = 1;
    public final static int TYPE_SCREEN360x360 = 2;
    public MyGame game;
    public View view;
    public int width;
    public int height;
    public int delay;
    public int state, beforeState;
    public int type;
    public int kindSwitchScreen;
    public String strBuffer = "";

    public Screen(MyGame game) {
        this.game = game;
        width = this.game.getScreenWidth();
        height = this.game.getScreenHeight();
        delay = this.game.getDelay();
        if (width > 220 && height > 300) {
            type = TYPE_SCREEN240x320;
        } else if (width > 300 && height > 220) {
            type = TYPE_SCREEN320x240;
        } else if (width > 320 && height > 320) {
            type = TYPE_SCREEN360x360;
        } else {
            type = TYPE_SCREEN240x320;
        }
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    public void setState(int newState) {
        beforeState = state;
        state = newState;
    }

    public void setView(View view) {
        if (this.view != null) {
            this.view.pause();
            this.view.dispose();
        }
        this.view = null;
        Runtime.getRuntime().gc();
        this.view = view;
//        this.view.resume();
//        this.view.update();
    }

    public void showView() {
        this.view.show(true);
    }

    public void dismissView() {
        this.view.show(false);
    }

    public abstract void init();

    public abstract void update();

    public abstract void present(Graphics g);

    public abstract void pause();

    public abstract void resume();

    public abstract void dispose();

    public abstract void handleSms(boolean success);

    public abstract void switchScreen();

    // <editor-fold defaultstate="collapsed" desc="KeyPressed">
    public abstract void upKeyPressed();

    public abstract void downKeyPressed();

    public abstract void rightKeyPressed();

    public abstract void leftKeyPressed();

    public abstract void fireKeyPressed();

    public abstract void softKeyLeftPressed();

    public abstract void softKeyRightPressed();

    public abstract void numberKeyPressed(int keyCode);
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="KeyReleased">
    public abstract void upKeyRealeased();

    public abstract void downKeyRealeased();

    public abstract void rightKeyRealeased();

    public abstract void leftKeyRealeased();// </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="KeyRepeated">
    public abstract void upKeytRepeated();

    public abstract void downKeyRepeated();

    public abstract void rightKeyRepeated();

    public abstract void leftKeyRepeated();// </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="TouchHandler">
    public abstract void pointerPressed(int x, int y);

    public abstract void pointerReleased(int x, int y);

    public abstract void pointerDragged(int x, int y);// </editor-fold>

    public boolean inBounds(int pointerX, int pointerY, int boxX, int boxY, int width,
            int height) {
        if (pointerX > boxX && pointerX < boxX + width - 1 && pointerY > boxY
                && pointerY < boxY + height - 1) {
            return true;
        } else {
            return false;
        }
    }
}
